package servlet;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.vo.RemitoClienteVO;

import service.SistemaCVR;

/**
 * Servlet implementation class EnviarMercaderiaClientes
 */
public class EnviarMercaderiaClientes extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EnviarMercaderiaClientes() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			request.setAttribute("tipo", "solicitud de envio de mercaderia a clientes");
			String nombreODV = request.getParameter("nombreODV");
			List<RemitoClienteVO> remitos = SistemaCVR.generarEnviosParaClienteDeOdv(nombreODV);
			request.setAttribute("remitos", remitos);
			RequestDispatcher dispatcher = request.getRequestDispatcher("/verRemitos.jsp");
			dispatcher.forward(request, response);
			
		}catch (Exception e) {
			request.setAttribute("error", "Intente nuevamente.");
			RequestDispatcher dispatcher = request.getRequestDispatcher("/resultadoRegistrar.jsp");
			dispatcher.forward(request, response);
		}
	}

}
